package com.jn.gsondemo.views;


import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.jn.gsondemo.R;
import com.jn.gsondemo.adapter.MedalRankAdapter;
import com.jn.gsondemo.entity.MedalData;
import com.jn.gsondemo.utils.JsonUtils;

import java.util.List;

public class MedalRankActivity extends AppCompatActivity {

    private MedalRankAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_medal_rank);

        // 获取JSON数据
        String json = JsonUtils.getJsonFromAssets(this, "olympic.json");

        // 解析数据
        List<MedalData> medalList = JsonUtils.jsonToList(json, MedalData.class);

        // 设置RecyclerView
        RecyclerView recyclerView = findViewById(R.id.recycler_view);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        adapter = new MedalRankAdapter(medalList);
        recyclerView.setAdapter(adapter);
    }
}